import 'package:flutter/material.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/image_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/parts_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/repair_car_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/repair_order_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/ticket_info.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

import 'order_widget/labor_hour.dart';

//修理厂 待结算
class AwaitBalance extends StatefulWidget {
  //{title}
  final Map<String, dynamic> arguments;

  const AwaitBalance({Key key, this.arguments}) : super(key: key);

  @override
  _AwaitBalanceState createState() => _AwaitBalanceState();
}

class _AwaitBalanceState extends State<AwaitBalance>
    with TickerProviderStateMixin {
  TabController _tabController; //tab控制器
  List<String> titleList = ["订单信息", "车辆信息", "图片信息"];
  bool invoiceInfoShow = false; //显示隐藏回票信息

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = new TabController(length: titleList.length, vsync: this);

    _tabController.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        backgroundColor: YTStyle.bgColor,
        appBar: AppBar(
          elevation: 0.5,
          centerTitle: true,
          backgroundColor: Colors.white,
          title: Text(
            widget.arguments["title"] as String,
            style: TextStyle(
                color: Color(0xff323232),
                fontSize: setSp(18),
                fontWeight: FontWeight.w600),
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          bottom: TabBar(
            controller: _tabController,
            isScrollable: true,
            labelColor: YTTheme.theme,
            labelStyle:
                TextStyle(fontSize: setSp(17), fontWeight: FontWeight.w600),
            unselectedLabelColor: Color(0xff323232),
            unselectedLabelStyle:
                TextStyle(color: Colors.white, fontSize: setSp(17)),
            indicatorColor: YTTheme.theme,
            indicatorSize: TabBarIndicatorSize.label,
            tabs: titleList
                .asMap()
                .map((key, value) {
                  return MapEntry(key, _tabItem(titleList[key]));
                })
                .values
                .toList(),
          ),
          leading: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              Navigator.pop(context);
            },
            child: Row(
              children: [
                Container(
                    margin: EdgeInsets.only(left: setWidth(15)),
                    width: setWidth(10),
                    height: setWidth(17),
                    child: Image.asset(
                      "assets/images/return.png",
                      fit: BoxFit.cover,
                    )),
              ],
            ),
          ),
          actions: [
            Container(
              margin: EdgeInsets.only(right: setWidth(15)),
              width: setWidth(10),
              height: setWidth(17),
            ),
          ],
        ),
        body: CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: SizedBox(
                height: setWidth(15),
              ),
            ),
            //订单信息
            SliverToBoxAdapter(
              child: Container(
                padding: EdgeInsets.only(
                    left: setWidth(15),
                    right: setWidth(15),
                    bottom: setWidth(15)),
                color: Colors.white,
                child: _checkType(_tabController.index),
              ),
            ),

            SliverToBoxAdapter(
              child: SizedBox(
                height: setWidth(15),
              ),
            ),
            //配件信息
            SliverToBoxAdapter(
              child: PartsInfo(),
            ),
            SliverToBoxAdapter(
              child: SizedBox(
                height: setWidth(15),
              ),
            ),
            //工时信息
            SliverToBoxAdapter(
              child: LaborHour(),
            ),
            //结算信息
            SliverToBoxAdapter(
              child: Container(
                  margin: EdgeInsets.only(top: setWidth(15)),
                  child: autoMakersSettlement(
                      price: "600", serve: "600", sum: "1460.00")),
            ),
            //回票信息
            SliverToBoxAdapter(
              child: TicketInfo(),
            ),
            SliverToBoxAdapter(
              child: SizedBox(
                height: setWidth(22),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _tabItem(String title) {
    return Tab(text: title);
  }

  //切换view
  // ignore: missing_return
  Widget _checkType(int type) {
    switch (type) {
      case 0:
        return RepairOrderInfo(
          orderState: widget.arguments["title"] as String,
        );
        break;
      case 1:
        return RepairCarInfo();
        break;
      case 2:
        return ImageListInfo();
        break;
    }
  }
}
